<?php

/**
 * Created by PhpStorm.
 * User: hhh
 * Date: 2016/12/28
 * Time: 9:52
 */
class Category extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Category_m','category');
    }

    function getCategories($parentId=0){
        $results=$this->category->getCategories($parentId);
        if(isset($results)){
            $mess="数据获取成功";
            $code=0;
        }else{
            $mess="数据获取失败";
            $code=1;
        }
        $arr=array(
            'code'=>$code,
            'message'=>$mess,
            'data'=>$results
        );
        echo json_encode($arr);
    }

    function getCategory($id){
        $results=$this->category->getCategory($id);
        if(isset($results)){
            $mess="数据获取成功";
            $code=0;
        }else{
            $mess="数据获取失败";
            $code=1;
        }
        $arr=array(
            'code'=>$code,
            'message'=>$mess,
            'data'=>$results
        );
        echo json_encode($arr);
    }
}